package com.example.mvpdemo2;

import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.mvpdemo2.mvpBase.BaseActivity;
import com.example.mvpdemo2.appInterface.LoginInterface;

public class LoginActivity extends BaseActivity<LoginPresenter,LoginInterface.VP> {


    //https://www.bilibili.com/video/BV1oC4y1a7u1


    EditText etName;
    EditText etPwd;
    Button btnLogin;


    @Override
    public LoginInterface.VP getContract() {
        return new LoginInterface.VP() {
            @Override
            public void requestLogin(String name, String password) {
                mPresenter.getContract().requestLogin(name,password);
            }

            @Override
            public void responseLogin(Boolean Result) {
                Toast.makeText(LoginActivity.this, Result?"Success":"Fail", Toast.LENGTH_SHORT).show();
            }
        };
    }

    @Override
    public void initView() {
        etName = (EditText) findViewById(R.id.et_username);
        etPwd = (EditText) findViewById(R.id.et_password);
        btnLogin = (Button) findViewById(R.id.btn_login);
    }

    @Override
    public void initListener() {
        btnLogin.setOnClickListener(this);
    }

    @Override
    public void initData() {
        etName.setText("abc");
        etPwd.setText("123");
    }

    @Override
    public int getContextViewID() {
        return R.layout.activity_main;
    }

    @Override
    public LoginPresenter getmPresenterInstance() {
        return new LoginPresenter();
    }

    @Override
    public void destroy() {

    }

    @Override
    public void onClick(View view) {
        getContract().requestLogin(etName.getText().toString(),etPwd.getText().toString());
        System.out.println("LoginActivity onclick");
    }

//    @Override
//    public void requestLogin(String name, String password) {
//        mPresenter.requestLogin(name,password);
//        System.out.println("View RequestLogin");
//    }
//
//    @Override
//    public void responseLogin(Boolean Result) {
//        Toast.makeText(LoginActivity.this, Result?"Success":"Fail", Toast.LENGTH_SHORT).show();
//    }
}